package com.swdegao.iot.netty.server.dongjianhandler;

import com.swdegao.iot.netty.entity.Parameter;
import com.swdegao.iot.netty.server.channelhandler.HeartBeatClientHandler;
import com.swdegao.iot.netty.server.decoder.DG_DATADecoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

public class DongJianChannelInitializer extends ChannelInitializer<SocketChannel> {
	 private EventLoopGroup pusheventloop  = new NioEventLoopGroup();

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline().addLast(new IdleStateHandler(Parameter.heartbeat_cycle_check,0,0, TimeUnit.SECONDS));
        socketChannel.pipeline().addLast(new DongJian_DATADecoder(1<<20,13,1,-14,0));
        socketChannel.pipeline().addLast(new HeartBeatClientHandler());
        socketChannel.pipeline().addLast(new DongJianParseMessgaeHandler());
        socketChannel.pipeline().addLast(new DongJianSaveMessgaeHandler());
        socketChannel.pipeline().addLast(pusheventloop,new DongJianPushMessgaeHandler());



    }
}
